/*
 * Copyright 2011 The Rusted Roof, LLC.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package org.proteusframework.platformservice.persistence.api.messagebean;

import org.proteusframework.core.api.model.IDescriptor;
import org.proteusframework.core.api.model.IMetadata;
import org.proteusframework.core.api.model.INamespace;

import java.util.List;

/**
 * Provides an agnostic representation of a message bean, including field names, data types, and a mapping class
 * used at runtime to map to the given message bean.
 * <p/>
 * Every message bean descriptor must be associated with a given <code>INamespace</code>; however, this does not imply
 * that every concrete message bean must itself implement <code>INamespace</code>. The namespace is used by the
 * persistence implementation to provide namespace guarantees between two disparate instances of a <code>Foo</code>
 * POJO.
 *
 * @author Tacoma Four
 */
public interface IMessageBeanDescriptor extends INamespace, IDescriptor, IMetadata, Comparable<INamespace>
{
    /**
     * Canonical name suitable for use within a <code>Class.forName()</code> invocation. The name described here may
     * or may not mirror the namespace description provided via the <code>INamespace</code> implementation.
     *
     * @return Canonical name of the class that implements the message bean described herein
     */
    String getCanonicalName();

    /**
     * One or more message properties definitions describing the properties of the message bean.
     *
     * @return Non-null, unmodifiable list with one or more message field definitions. Persistence services may choose to ignore
     *         the sorting order implicitly defined by the backing list.
     */
    List<IMessageBeanProperty> properties();

    /**
     * Obtains a subset list of message bean properties defined within the context of this descriptor. This method is
     * particularly useful when assembling a list of message bean properties in order to execute an
     * {@link org.proteusframework.platformservice.persistence.api.IMessageBeanManager#updateMessage(Class, Object, IMessageBeanProperty...)}
     * command.
     *
     * @param propertyNames Property names
     * @return Non-null array of message bean properties that match the list of names provided
     * @throws IllegalArgumentException when one of the named properties is not defined within the context of this descriptor
     */
    IMessageBeanProperty[] lookupSpecificProperties(String... propertyNames);

    /**
     * Optional list of message index requests. Not every persistence service implementation will support indexing, and
     * the specific index creation (or lack thereof) should be verified with the specific persistence service.
     *
     * @return Non-null list of suggested index definitions offered to the persistence service for consideration. List
     *         may be empty.
     */
    List<IMessageBeanIndex> indices();

    /**
     * Optional list of interfaces that the message bean implements. Persistence services may support working with
     * interface types in lieu of concrete class names.
     *
     * @return Non-null list of interfaces supported by the message bean. List may be empty.
     */
    List<Class<?>> interfaces();

    /**
     * Flag that indicates if this message bean declares one or more identity columns. The underlying persistence
     * service determines if identity columns are supported, and the rules of use within a singular message bean.
     *
     * @return true, if message bean defines an identity column
     */
    boolean hasIdentityColumn();

    /**
     * Array of identity columns declared by the message bean, if any.
     *
     * @return Non-null array of identity columns
     */
    String[] getIdentityColumn();
}
